<?php 
namespace App\Services;
use App\Facades\Utils\ValidateParameter;
use App\Facades\Infra\FrontManager;


class SubmitService{

	public function create($request){
		$rules = [
			'name' => 'required',
			'phone' => 'required|numeric',
			'age' => 'numeric',
			'sex' => 'boolean',
			'weight' => 'numeric',
			'bmi' => 'numeric',
			'province_id' => 'exists:provinces,id',
			'history' => 'numeric'
		];

		ValidateParameter::validate($request,$rules);

		$data=$request->all();

		$info['name'] = $data['name'];

		$info['phone'] = $data['phone'];

		if(isset($data['age']) && $data['age'] != ""){
			$info['age'] = $data['age'];
		}
		if(isset($data['sex']) && $data['sex'] != ""){
			$info['sex'] = $data['sex'];
		}
		if(isset($data['weight']) && $data['weight'] != ""){
			$info['weight'] = $data['weight'];
		}
		if(isset($data['bmi']) && $data['bmi'] != ""){
			$info['bmi'] = $data['bmi'];
		}
		if(isset($data['province_id']) && $data['province_id'] != ""){
			$info['province_id'] = $data['province_id'];
		}
		if(isset($data['history']) && $data['history'] != ""){
			$info['history'] = $data['history'];
		}

		FrontManager::createSubmit($info);
	}

	public function getAll(){
		return FrontManager::getSubmits();
	}
}